package com.zyg.jas.studentport.controller;

import com.zyg.jas.common.pojo.Homework;
import com.zyg.jas.common.pojo.Score;
import com.zyg.jas.studentport.service.HomeworkService2;
import com.zyg.jas.studentport.service.ScoreService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

@Controller
@RequestMapping("/sport/score")
@CrossOrigin
public class ScoreController2{
    @Autowired
    private ScoreService2 scoreService;

    // 保存我的作业
    @RequestMapping(value = "/saveHomework",method = RequestMethod.POST)
    @ResponseBody
    public Integer saveHomework(@RequestParam("resourceFile")MultipartFile multipartFile,
                                @RequestParam("hId") Integer hId, @RequestParam("sNo") String sNo,@RequestParam("comId") String comId) throws Exception {
        Score score = new Score();
        score.setComId(comId);
        score.sethId(hId);
        System.out.println("后台输出 +"+hId);
        score.setsNo(sNo);
        try {
            return this.scoreService.saveHomework(multipartFile,hId,sNo,comId);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    // 保存我的作业
    @RequestMapping(value = "/saveHomeworkForApp",method = RequestMethod.POST)
    @ResponseBody
    public Integer saveHomework(@RequestParam("resourceFile")MultipartFile multipartFile,@RequestParam("fileName") String fileName,
                                @RequestParam("hId") Integer hId, @RequestParam("sNo") String sNo,@RequestParam("comId") String comId) throws Exception {
        System.out.println("app接收到的作业");
        System.out.println(fileName);
        System.out.println(multipartFile.getOriginalFilename());
        Score score = new Score();
        score.setComId(comId);
        score.sethId(hId);
        score.setCommitName(fileName); //add
        System.out.println("后台输出 +"+hId);
        score.setsNo(sNo);
        try {
            return this.scoreService.saveHomeworkForApp(multipartFile,fileName,hId,sNo,comId);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }


    // 获得我的所有提交记录
    @RequestMapping(value = "/selectMyScore/{hId}/{sNo}/{comId}",method = RequestMethod.GET)
    @ResponseBody
    public List<Score> selectMyScore(@PathVariable("hId") Integer hId, @PathVariable("sNo") String sNo, @PathVariable("comId") String comId) {
        return this.scoreService.selectMyScore(hId,sNo,comId);
    }



    // 删除我的提交
    @RequestMapping(value = "/deleteById/{id}")
    @ResponseBody
    public Integer deleteById(@PathVariable("id") Integer id){
        return this.scoreService.deleteById(id);
    }


    }
